package cn.bigcontainer.alt.sys.exception;

import java.util.Map;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class AjaxHtmlExceptionHandler implements MethodInterceptor {

	@Override
	public Object invoke(MethodInvocation mi) throws Throwable {
		try {
			// 目标方法调用
			return mi.proceed();
		} catch (Exception e) {
			log.error("", e);
			for (Object arg : mi.getArguments()) {
				if (arg instanceof Map) {
					Map<String, Object> map = (Map<String, Object>)arg;
					map.put("error", e.getMessage());
				}
			}
			return "error.ajaxhtml";
		}
	}

}
